package com.example.neo4j.controller;

import com.example.neo4j.pojo.util.ResponseInfo;
import com.example.neo4j.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Controller
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("/praised/unzan")
    @ResponseBody
    public ResponseInfo unPraiseShare(@RequestParam("account") String account, @RequestParam("shareid") Integer shareid) {
        return userService.unpraiseShare(account, shareid);

    }

    @PostMapping("/praised/zan")
    @ResponseBody
    public ResponseInfo praiseShare(@RequestParam("account") String account, @RequestParam("shareid") Integer shareid) {
        return userService.praiseShare(account, shareid);
    }

    @GetMapping("/recommend/user/byfriend")
    public String recommendFriendsByFriend(HttpServletRequest request, Map<String, Object> map) {
        return userService.recommendFriendsByFriend(request, map);
    }

    @PostMapping("/follow/unfollow")
    @ResponseBody
    public ResponseInfo unfollow(@RequestParam("follower") String follower, @RequestParam("following") String following) {
        return userService.unfollow(follower, following);
    }

    @GetMapping("/user/follower")
    public String getFans(HttpServletRequest request, Map<String, Object> map) {
        return userService.getFans(request, map);
    }


    @GetMapping("/user/myfollowing")
    public String getMyFollowing(HttpServletRequest request, Map<String, Object> map) {
        return userService.getMyFollowing(request, map);
    }

    @PostMapping("/follow/followit")
    @ResponseBody
    public ResponseInfo followIt(@RequestParam("follower") String follower, @RequestParam("following") String following) {
        return userService.followIt(follower, following);
    }

    @GetMapping("/logout")
    public String logout(HttpServletRequest request) {
        return userService.logout(request);
    }


    //根据共同爱好推荐好友
    @GetMapping("/recommend/user/byhobby")
    public String recommendFriendsByHobby(HttpServletRequest request, Map<String, Object> map) {
        return userService.recommendFriendsByHobby(request, map);
    }

    @PostMapping("/user/unlike")
    @ResponseBody
    public ResponseInfo unlikeHobby(@RequestParam("account") String account,
                                    @RequestParam("hobbyid") Long hobbyid) {
        return userService.unlikeHobby(account, hobbyid);
    }

    @PostMapping("/user/like")
    @ResponseBody
    public ResponseInfo likeHobby(@RequestParam("account") String account,
                                  @RequestParam("hobbyid") Long hobbyid) {
        return userService.likeHobby(account, hobbyid);
    }

    @PostMapping("/login")
    public String index(@RequestParam("account") String account,
                        @RequestParam("password") String password,
                        Map<String, Object> paramMap,
                        HttpServletRequest request) {
        return userService.index(account, password, paramMap, request);
    }

    @GetMapping("/content")
    public String content(HttpServletRequest request, Map<String, Object> paramMap) {
        return userService.content(request, paramMap);
    }

    @PostMapping("/user/adduser")
    public String addUser(@RequestParam("account") String account,
                          @RequestParam("password") String password,
                          @RequestParam("age") Integer age,
                          @RequestParam("gender") String gender,
                          @RequestParam("email") String email,
                          @RequestParam("address") String address,
                          @RequestParam("nickname") String nickname,
                          Map<String, Object> map) {
        return userService.addUser(account, password, age, gender, email, address, nickname, map);
    }

    @GetMapping("/")
    public String index() {
        return userService.index();
    }

    @GetMapping("/register")
    public String register() {
        return "register";
    }
}
